const app = getApp()
const db = wx.cloud.database({})

Page({
  data:{
    selectedQsid:'this is the pickedID',
    selectedTiltle:'',
    openid:'',
    querys:[],
    windowHeight: 0,
    windowWidth: 0,
    Liststate:true,
  },
  onShow: function () {
    wx.cloud.callFunction({
      name:'getOpenId',
    }).then(res=>{
      console.log("查询到的openid为"+res.result.openid)
      this.setData({
        openid:res.result.openid
      })
      db.collection("questions").where({
      _openid:this.data.openid
    }).get().then(res=>{
      console.log("查询得到的问卷有： ")
      console.log(res.data)
      this.setData({
        querys:res.data
      })
      console.log(this.data.querys)
    })
    })  
  },
  onReady:function () {
    wx.getSystemInfo({
      success:res=>{
        this.setData({
          windowWidth:res.windowWidth,
          windowHeight:res.windowHeight
        })
      }
    })
  },
  navigateToStats:function(e){
    console.log("点击的按钮id："+e.currentTarget.dataset.value)
    this.setData({
      selectedQsid:e.currentTarget.dataset.value
    })
    db.collection("questions").where({
      q_id:this.data.selectedQsid
    }).get({
      success:(res)=>{
        this.setData({
          selectedTiltle:res.data[0].name
        })
        wx.navigateTo({
          url: '../stat/statistics?selectedQsid='+this.data.selectedQsid+'&selectedTitle='+this.data.selectedTiltle
        })
      }
    } )
  },

  ListCheckedFalse(){
    this.setData({
      Liststate:false
    })
  },
  ListCheckedTrue(){
    this.setData({
      Liststate:true
    })
  }
})
